// 匿名函数
(async function() {
	var params = getJsParams('macro_idcard_ctl');
    var fieldName = params.fieldName;
    var formCode = params.formCode;
    var birthField = params.birthField;
    
    $(fo(fieldName)).change(function() {
        var obj = this;
        console.log(fieldName, $(this).val());
        console.log('birthField=' + birthField);
        if ($(this).val()=="") {
            return;
        }
    
        var isMap = birthField != '';
        console.log('isMap', isMap);
    
        var ajaxData = {
            val: $(this).val()
        };
        ajaxPost('/module_check/checkIDCard', ajaxData).then((res) => {
            var data = res.data;
            console.log('data', data);
            if (data.ret==0) {
                // console.log('msg=' + data.msg);
                $('#errMsgBox_' + fieldName).remove();
                $(obj).parent().append("<span id='errMsgBox_" + fieldName + "' class='LV_validation_message LV_invalid'>" + data.msg + "</span>");
                if (isMap) {
                    if (typeof(findObj(birthField).value)=="string") {
                        fo(birthField).value = "";
                    }
                    else {
                        fo(birthField).innerHTML = "";
                    }
                }
            }
            else {
                $('#errMsgBox_' + fieldName).remove();
                if (isMap && findObj(birthField)) {
                    if (typeof(findObj(birthField).value)=="string") {
                        findObj(birthField).value = data.birthday;
                    }
                    else {
                        findObj(birthField).innerHTML = data.birthday;
                    }
                }
            }
        });
    })     
})();
